package com.yuke.cloud.service.pmc.service.impl;

import com.yuke.cloud.common.core.support.BaseService;
import com.yuke.cloud.service.api.smc.dto.ShopInfoDto;
import com.yuke.cloud.service.pmc.dao.DicRegionMapper;
import com.yuke.cloud.service.pmc.dto.ProvinceAndCityInfoDto;
import com.yuke.cloud.service.pmc.entity.DicRegion;
import com.yuke.cloud.service.pmc.service.DicRegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * Created by zys on 2018/09/30.
 */
@Slf4j
@Service
@Transactional
public class DicRegionServiceImpl extends BaseService<DicRegion> implements DicRegionService {
    @Resource
    private DicRegionMapper dicRegionMapper;

    @Override
    public int save(DicRegion record) {
        record.setRegionId(generateId());
        return super.save(record);
    }

    @Override
    public List<ShopInfoDto> getRegionNameByRegionIds(List<ShopInfoDto> shopInfoDtos) {
        if(shopInfoDtos!=null){
            for (ShopInfoDto shopInfoDto : shopInfoDtos) {
            shopInfoDto.setRegionProvinceName(selectByKey(shopInfoDto.getRegionProvinceId()).getRegionName());
            shopInfoDto.setRegionCityName(selectByKey(shopInfoDto.getRegionCityId()).getRegionName());
            shopInfoDto.setRegionCountyName(selectByKey(shopInfoDto.getRegionCountyId()).getRegionName());
          }
        }

        return shopInfoDtos;
    }

    @Override
    public List<DicRegion> listExcludeCounty() {
        return dicRegionMapper.listExcludeCounty();
    }

    @Override
    public ProvinceAndCityInfoDto getProvinceAndCityInfoByCityId(Long cityId) {
        return dicRegionMapper.getProvinceAndCityInfoByCityId(cityId);
    }

    @Override
    public List<Map> getRegionNameByCountyIds(List<Long> countys)  {
        return dicRegionMapper.getRegionNameByCountyIds(countys);
    }
}
